function DatumManage() {
    var _this = this;
    var page;
    _this.page_size = 10;

    // init
    _this.init = function(_page) {
        page = _page;
        _this.initTable();
        _this.initEvent();
    }

    _this.initTable = function() {
        var list_url = appPath + "/admin/projectOffline/datumList";
        page.init("projectDatumForm", list_url, "datum_list", "datum_page", 1, _this.page_size);
        page.goPage(1);
        page.list = function(dataList){
            _this.obj = dataList;
            if(dataList == null){
                return;
            }
            var len = dataList.length;
            var inner = "", item;
            // 组装数据
            for(var i=0; i< len; i++) {
                item = dataList[i];
                // 组装数据
                inner += "<tr>";
                inner += "<td>"+(parseInt(i)+1)+"</td>";
                inner += "<td><input type='checkbox' value='"+item.datumId+"'/></td>";
                inner += "<td><span class=\"text-orange tooltip\" data-length='30'>"+item.datumName+"</span></td>";
                inner += "<td>"+item.datumType+"</td>";
                inner += "<td>"+item.attachmentCount+"</td>";
                inner += '<td>';
                // inner += '<a href="javascript:projectOffline.projectInfo(\''+item.id+'\');" class="a a-view">详情</a> ';
                inner += '<a href="javascript:datumManage.datumModify(\''+item.datumId+'\');" class="a a-info">修改</a>';
                inner += '<a href="javascript:datumManage.datumView(\''+item.datumId+'\');" class="a a-view">预览</a> ';
                inner += '<a href="javascript:datumManage.datumDownload(\''+item.datumId+'\',\''+item.attachmentCount+'\',\''+item.datumName+'\');" class="a a-info">下载</a> ';
                inner += "</td>";
                inner += "</tr>";
            }
            return inner;
        }

    };

    _this.initEvent = function () {
        //搜索
        $("#btn_search").click(function () {
            _this.initTable();
        });

        //全部
        $("#btn_search_all").click(function () {
            $("#datumName").val("");
            _this.initTable();
        });
    }


    // 新增
    _this.datumAdd = function (projectId) {
        var url = appPath + "/admin/projectOffline/goAddDatum?projectId="+projectId;
        window.open(url,"_blank");
    }

    // 批量删除
    _this.deleteBatch = function () {
        var datumIds=[]
        $('#datum_list input:checked').each(function(i,e){
            datumIds.push($(this).val());
        });
        if(datumIds.length==0){
            layer.msg("请选择要删除的行 !",{icon:7});return;
        }
        layer.confirm("确定此操作吗?", {
            icon : 3,
            btn : [ "确认", "取消" ]
        }, function() {
            $.ajax({
                url: appPath + '/admin/projectOffline/deleteDatum',
                async: false,
                type: 'post',
                data: {
                    'projectId': $("#projectId").val(), 	            // 项目总览id
                    'datumIds': datumIds.join(",")	                        // 人员ids
                },
                success: function(data){
                    var code = data['code'];
                    if(code){
                        layer.alert('操作成功', {icon: 1,  skin: 'layer-ext-moon', closeBtn:0}, function(index){
                            layer.close(index);
                            _this.initTable();
                        });
                    }else{
                        layer.alert('操作失敗', {icon: 2,  skin: 'layer-ext-moon'});
                    }
                }
            });
        });
    }


    // 修改
    _this.datumModify = function (datumId) {
        var url = appPath + "/admin/projectOffline/datumModify?datumId=" + datumId;
        window.open(url,"_blank");
    }

    // 预览
    _this.datumView = function (datumId) {
        var url = appPath + "/admin/projectOffline/datumView?datumId=" + datumId;
        window.open(url,"_blank");
    }

    // 下载资料里的所有附件zip
    _this.datumDownload = function (datumId, attachmentCount, datumName) {
        if(0 == attachmentCount){
            layer.alert("该资料下暂无附件",{icon:7});
        }else{
            var fileName = datumName + ".zip";
             window.location.href = appPath + '/attachment/downloadDatum?datumId='+ datumId + '&fileName=' + fileName;
        }
    }

}

var datumManage = new DatumManage();